/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

API.grid = API.grid || {};
API.grid.BasicGrid = function(config) {
    
    API.apply(this, config, {});
    
    var t = document.createElement('table');
        t.className = 'imagetable';
        t.border = 1;
        
    var tr = document.createElement('tr');

    var th1 = document.createElement('th');
        th1.textContent = 'Nombre';
        tr.appendChild(th1);
    var th2 = document.createElement('th');
        th2.textContent = 'Dirección';
        tr.appendChild(th2);
    var th3 = document.createElement('th');
        th3.textContent = 'Celular';
        tr.appendChild(th3);
    var th4 = document.createElement('th');
        th4.textContent = 'Teléfono Particular';
        tr.appendChild(th4);
    var th5 = document.createElement('th');
        th5.textContent = 'Correo Electrónico';
        tr.appendChild(th5);
    
    t.appendChild(tr);
        
    this.DOM = t;
        
    this.getGrid = function(){
        return this.DOM;
    };

    this.insertRow = function(data/*, id*/){

        var grid = this.getGrid();

        var row = grid.insertRow(grid.rows.length);

        var index = 0;

        /*var cell0 = row.insertCell(index);
        cell0.innerHTML = data.id || id;
        cell0.style = 'display:none';
        index++;*/

        var cell1 = row.insertCell(index);
        cell1.innerHTML = data.name;

        index++;
        var cell2 = row.insertCell(index);
        cell2.innerHTML = data.direccion;

        index++;
        var cell3 = row.insertCell(index);
        cell3.innerHTML = data.celular;

        index++;
        var cell4 = row.insertCell(index);
        cell4.innerHTML = data.telefono;

        index++;
        var cell5 = row.insertCell(index);
        cell5.innerHTML = data.email;

    };

    this.load = function(){
        var me = this;        
        this.store.forEachValue(function(value){
            me.insertRow(value);
        });
    };

    this.clear = function(){            
        var table = this.getGrid();
        for (var i=table.rows.length-1; i>0; i--) 
           table.deleteRow(i);                        
    };

    this.refresh = function(){            
        this.clear();
        this.load();            
    };
};
